<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="path" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
<base href="${path}/pages/">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>学生管理系统</title>
<link rel="stylesheet" href="../layui/css/layui.css">
</head>
<body>
	
<div class="layui-fluid">
		
	<div class="layui-form" style="margin-top:10px">
		<input type="hidden" name="id" value="${clazz.id }">
  		<div class="layui-form-item">
    		<label class="layui-form-label">班级名称</label>
    		<div class="layui-input-block">
      			<input type="text" name="name" value="${clazz.name }" lay-verify="required" placeholder="请输入班级名称" autocomplete="off" class="layui-input">
    		</div>
  		</div>
  		<div class="layui-form-item layui-form-text">
    		<label class="layui-form-label">班级备注</label>
    		<div class="layui-input-block">
      			<textarea id="note" name="note" style="display:none;" placeholder="请输入内容" class="layui-textarea">${clazz.note }</textarea>
    		</div>
  		</div>
  		
  		<div class="layui-form-item">
    		<label class="layui-form-label">图片路径</label>
    		<div class="layui-input-block">
      			<input type="text" name="picPath" id="picPath" class="layui-input">
    		</div>
  		</div>
  		
  		<div class="layui-form-item">
  			<div class="layui-input-block">
  				<button type="button" class="layui-btn" id="test1">
			  		<i class="layui-icon">&#xe67c;</i>上传图片
				</button>
  			</div>
  		</div>
  		
  		
  		<div class="layui-form-item layui-hide">
	      	<input type="button" lay-submit lay-filter="lay-form-submit" id="lay-form-submit">
	    </div>
  		
  	</div>
</div>

<script src="../layui/layui.js"></script>
<script>
	layui.use(['form', 'upload', 'layedit'], function() {
		var form = layui.form;
		var $ = layui.$;
		var upload = layui.upload;
		var layedit = layui.layedit;
		
		//富文本编辑器
		layedit.set({
  			uploadImage: {
    			url: '${path}/action/student/upload'
  			}
		});
  		var editObj = layedit.build('note'); 
		
		//文件上传： ajax, name="file"
		upload.render({
    		elem: '#test1', //绑定元素
    		url: '${path}/action/student/upload', //上传接口
    		done: function(res) {
      			//上传完毕回调
      			alert(JSON.stringify(res));
      			if(res.success) {
      				$('#picPath').val(res.data.src);
      			}
    		}
		});
		
		//监听提交
    	form.on('submit(lay-form-submit)', function(data) {
    		// data.field：存放表单所有数据
    		// 获得编辑器的内容
    		var content = layedit.getContent(editObj);
    		data.field.note = content;
    		
      		var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引  
      		//提交ajax成功后，关闭当前弹层并重载表格
      		$.ajax({
      			type: 'post',
      			url: '${path}/action/clazz/save',
      			data: data.field,
      			success: function(json) {
      				parent.layui.table.reload('lay-table'); //重载表格
      	      		parent.layer.close(index); //再执行关闭      				
      			}
      		});
    	});
		
	});
	
</script>

</body>
</html>